package threadpoolnio;

import javax.swing.*;
import javax.swing.text.JTextComponent;
import java.io.OutputStream;
import java.io.PrintStream;

/**
 * @author ：xx
 * @date ：Created in 2020/2/27 21:08
 * @description：
 * @modified By：
 */
public class NetPrintStream extends PrintStream {
    public JTextComponent textArea;
    public StringBuffer sb=new StringBuffer();
    public NetPrintStream(OutputStream out, JTextComponent textArea) {
        super(out);
        this.textArea=textArea;
    }

    @Override
    public void write(byte[] buf, int off, int len) {
        final String message = new String(buf, off, len);
        SwingUtilities.invokeLater(new Runnable(){
            public void run(){
                sb.append(message);
                textArea.setText(sb.toString());
            }
        });
    }
}
